////////////////////////////////////////////////////////////////////////////////
//
//  nino
//
////////////////////////////////////////////////////////////////////////////////

package ochart.utils.logging
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	/**
	 * 日志仓库
	 * 用于存储日志供查询
	 */
	public class LogRepository extends EventDispatcher
	{
		
		private static var _instance:LogRepository = null;
		
		public static function get instance():LogRepository
		{
			if(!_instance)
			{
				_instance = new LogRepository();
				
			}
			return _instance;
		}
		
		/**
		 * 日志仓库
		 * 结构如下:
		 * repository : Dictionary
		 * |-ClassNameA : Dictionary
		 * | |-Debug : Array
		 * | \-Info : Array
		 * |-ClassNameB : Dictionary
		 * \-ClassNameC : Dictionary
		 */
		public var repository:Dictionary = new Dictionary();
		
		public function LogRepository(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function add(log:Log):Boolean
		{
			if(!log)
			{
				return false;
			}

			return true;
		}
		
		public function remove(log:Log):Boolean
		{
			if(!log)
			{
				return false;
			}
			
			return true;
		}
		
		public function clear():void
		{
			this.repository = new Dictionary();
		}
		
		public function getLogArrayByClassName(className:String, level:Level = null):Array
		{
			if(!className)
			{
				return null;
			}
			
			var dictionary:Dictionary = getLogDictionaryByClassName(className, level);
			if(!dictionary)
			{
				return null;
			}
			
			var levelArray:Array = Level.getEqualAndGreaterLevelArray(level);
			var array:Array = [];
			for each(var l:Level in levelArray)
			{
				// push level-array to array
			}
			return array;
		}
		
		public function getLogDictionaryByClassName(className:String, level:Level = null):Dictionary
		{
			if(!className || !repository)
			{
				return null;
			}
			
			var dictionary:Dictionary = repository[className];
			if(dictionary && level)
			{
				var levelArray:Array = Level.getLessLevelArray(level);
				for each(var l:Level in levelArray)
				{
					delete dictionary[l.levelStr];
				}
			}
			return dictionary;
		}
	}
}